package extract.knowledge.general;

import com.thinkaurelius.titan.core.TitanGraph;
import common.model.graph.MetaSchema;
import common.model.knowledge.BaseDoc.IDValuePair;
import extract.knowledge.concept.ConceptFactory;
import extract.knowledge.edgeclass.EdgeClassFactory;
import extract.knowledge.instance.InstanceFactory;
import org.apache.tinkerpop.gremlin.structure.Vertex;

/**
 * Created by Common on 8/1/16.
 */
public class VetexGenerator {


    public static String CONCEPT = "concept";
    public static String PROPERTY = "property";
    public static String INSTANCE = "instance";

    public static Vertex genVertex(TitanGraph graph, IDValuePair pair){
        String id_node = pair.getId();
        String name = pair.getValue();
        String ori_label = NodeParser.parse_label(id_node);
        Integer id = NodeParser.parse_id(id_node);
        if(id == NodeParser.INVALID_ID){
            return null;
        }
        Vertex vertex = vertexFactory(graph, ori_label, id, name);
        return vertex;
    }


    public static Vertex vertexFactory(TitanGraph graph, String ori_label, Integer id, String name){
        Vertex vertex = null;
        BaseFactory factory = null;
        if( ori_label.equals(CONCEPT) ){
            //ConceptFactory
            factory = new ConceptFactory(graph);
            //vertex = factory.getOrCreateVertex(id);
            //factory.setNameProperty(vertex, name);
        }
        else if( ori_label.equals(PROPERTY)){
            //EdgeClassFactory
            factory = new EdgeClassFactory(graph);
            //vertex = factory.getOrCreateVertex(id);
            //factory.setNameProperty(vertex, name);
        }
        else if( ori_label.equals(INSTANCE)){
            //InstanceFactory
            factory = new InstanceFactory(graph);
            //vertex = factory.getOrCreateVertex(id);
            //factory.setNameProperty(vertex, name);
        }
        vertex = factory.getOrCreateVertex(id);
        factory.setNameProperty(vertex, name);
        return vertex;

    }
}
